const {app, BrowserWindow, Tray, Menu} = require('electron');
const path = require("path");

let tray = null;
function createWindow() {
    const win = new BrowserWindow({
        transparent: true,
        fullscreen: true,
        frame: false,
        skipTaskbar: true,
        focusable: false,
        alwaysOnTop: true,
        webPreferences: {
            nodeIntegration: true,
            webSecurity: false,
            contextIsolation: false
        }
    });

    win.setMenu(null);
    win.loadFile('index.html');
    win.setIgnoreMouseEvents(true, {forward: true});
    // win.webContents.openDevTools()

    //创建系统通知区菜单
    tray = new Tray(path.join(__dirname, 'icon.ico'));
    const contextMenu = Menu.buildFromTemplate([
        {
            label: '退出', click: () => {
                win.destroy()
            }
        }
    ]);
    tray.setContextMenu(contextMenu);
}

app.whenReady().then(createWindow);

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit();
    }
});

app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
        createWindow();
    }
});
